
package cs422.group1.projectsquirrel;


import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;


public class ProjectSquirrel extends ListActivity {
	
	static Context myAppContext;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myAppContext = this;
        /*ViewGroup decorView= 
        	   (ViewGroup) getWindow().getDecorView();
        	LinearLayout root= (LinearLayout) decorView.getChildAt(0);
        	FrameLayout titleContainer= (FrameLayout) root.getChildAt(0);
        	TextView title= (TextView) titleContainer.getChildAt(0);
        	title.setGravity(Gravity.CENTER);
        */	
        	
        ListAdapter adapter = createListAdapter();
        setListAdapter(adapter);
        
               
    }
    
    protected void onListItemClick(ListView l, View v, int position, long id)
    { 
        super.onListItemClick(l, v, position, id);
        Intent intent = null;
        switch (position)
        {
        	case 0: // record observation
        		intent = new Intent(v.getContext(), RecordObservation.class);
        		if (ObservationDataManager.getData().observationDate != "")
        		{
        			ObservationDataManager.saveData(ObservationDataManager.getData());
        			ObservationDataManager.loadObservation(new ObservationData());
        			ObservationDataManager.editObservation = false;
        		}
        		break;
        	case 1: // observation history
        		intent = new Intent(v.getContext(), ObservationHistory.class);
        		break;
        	case 2: // contact us
        		intent = new Intent(v.getContext(), ContactUs.class);
        		break;
        	case 3: // help
        		intent = new Intent(v.getContext(), Help.class);
        		break;
        	case 4: // website
        		intent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.projectsquirrel.com"));
        		break;
        		
        	
        };
        if (intent != null)
        	startActivity(intent);
        
        
        	
    }

    
    protected ListAdapter createListAdapter()
    {
    	String[] values = new String[] {"Record observation", "Observation History", "Contact Us", "FAQ's", "ProjectSquirrel.com"};
    	ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.listtextview, R.id.row_number, values);
    	return adapter;
    }
    
   
    
}